"""
@FileName：4线程间的通信.py
@Author：lmz
@Time：2021/5/20 23:01
"""
import threading
import time
import queue

mes_que = queue.Queue(maxsize=10)
def backgroundthread(count):
    sum=0
    for i in range(1, count+1):
        time.sleep(0.1)
        if i%10==0:
            mes_que.put("{por}".format(por=i//10))
        sum = sum + i
    mes_que.put("total sum is {x}".format(x=sum))

def forgroundthread():
    while 1:
        got = mes_que.get()
        print(got)
        if got[:5] == 'total':
            break
    print('Done')

t1 = threading.Thread(target=backgroundthread, args=(100,))
t2 = threading.Thread(target=forgroundthread)
t1.start()
t2.start()